package io.renren.modules.efinance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.ShiroUtils;
import io.renren.modules.efinance.dao.BankcardDao;
import io.renren.modules.efinance.entity.BankcardEntity;
import io.renren.modules.efinance.service.BankcardService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("bankcardService")
public class BankcardServiceImpl extends ServiceImpl<BankcardDao, BankcardEntity> implements BankcardService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BankcardEntity> page = this.page(
                new Query<BankcardEntity>().getPage(params),
                new QueryWrapper<BankcardEntity>()
                        .eq("bankcard_username",params.get("bankcard_username"))
        );

        return new PageUtils(page);
    }

    @Override
    public int recharge(BankcardEntity bankcardEntity) {
        return baseMapper.recharge(bankcardEntity);
    }

    @Override
    public PageUtils queryUnbinds(Map<String, Object> params) {
        List<BankcardEntity> entities = baseMapper.queryUnbinds(ShiroUtils.getUserEntity().getUsername());
        return new PageUtils(entities,entities.size(),entities.size(),1);
    }

    @Override
    public PageUtils queryBinds(Map<String, Object> params) {
        List<BankcardEntity> entities = baseMapper.queryBinds(ShiroUtils.getUserEntity().getUsername());
        return new PageUtils(entities,entities.size(),entities.size(),1);
    }

}